//滚动
(function ($) {

    $.fn.kxbdMarquee = function (options) {
        var opts = $.extend({}, $.fn.kxbdMarquee.defaults, options);

        return this.each(function () {
            var $marquee = $(this);
            var _scrollObj = $marquee.get(0);
            var scrollW = $marquee.width();
            var scrollH = $marquee.height();
            var $element = $marquee.children();
            var $kids = $element.children();
            var scrollSize = 0;
            var _type = (opts.direction == 'left' || opts.direction == 'right') ? 1 : 0;
            $element.css(_type ? 'width' : 'height', 10000);
            if (opts.isEqual) {
                scrollSize = $kids[_type ? 'outerWidth' : 'outerHeight']() * $kids.length;
            } else {
                $kids.each(function () {
                    scrollSize += $(this)[_type ? 'outerWidth' : 'outerHeight']();
                });
            }
            if (scrollSize < (_type ? scrollW : scrollH)) return;
            $element.append($kids.clone()).css(_type ? 'width' : 'height', scrollSize * 2);
            var numMoved = 0;

            function scrollFunc() {
                var _dir = (opts.direction == 'left' || opts.direction == 'right') ? 'scrollLeft' : 'scrollTop';
                if (opts.loop > 0) {
                    numMoved += opts.scrollAmount;
                    if (numMoved > scrollSize * opts.loop) {
                        _scrollObj[_dir] = 0;
                        return clearInterval(moveId);
                    }
                }
                if (opts.direction == 'left' || opts.direction == 'up') {
                    _scrollObj[_dir] += opts.scrollAmount;
                    if (_scrollObj[_dir] >= scrollSize) {
                        _scrollObj[_dir] = 0;
                    }
                } else {
                    _scrollObj[_dir] -= opts.scrollAmount;
                    if (_scrollObj[_dir] <= 0) {
                        _scrollObj[_dir] = scrollSize;
                    }
                }
            }

            var moveId = setInterval(scrollFunc, opts.scrollDelay);
            $marquee.hover(
                function () {
                    clearInterval(moveId);
                },
                function () {
                    clearInterval(moveId);
                    moveId = setInterval(scrollFunc, opts.scrollDelay);
                }
            );

        });
    };
    $.fn.kxbdMarquee.defaults = {
        isEqual: true,
        loop: 0,
        direction: 'left',//滚动方向，'left','right','up','down'
        scrollAmount: 1,
        scrollDelay: 20

    };
    $.fn.kxbdMarquee.setDefaults = function (settings) {
        $.extend($.fn.kxbdMarquee.defaults, settings);
    };
})(jQuery);

//调用幻灯片
$(function () {
    $(".photoslide").KinSlideshow({
        intervalTime: 5,
        titleFont: {TitleFont_size: 12, TitleFont_color: "#fff"},
        btn: {btn_bgHoverColor: "#c60000", btn_borderHoverColor: "#c60000", btn_fontHoverColor: "#aaaa", btn_borderWidth: 3, btn_bgColor: "#333", btn_fontColor: "#fff", btn_borderColor: "#333" }
    });
});